package cn.cryengine3.com.kvmaker;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
    private MainNativBridge mainNativBridge;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mainNativBridge = new MainNativBridge();
        ((TextView) findViewById(R.id.tv_1)).setText(mainNativBridge.stringFromJNI());
        ((TextView) findViewById(R.id.tv_2)).setText(MainNativBridge.staticFromJNI());
        String str = "Java传递string 给jni 在jni层打印数据";
        mainNativBridge.postValue2JNI(str);
        ((TextView) findViewById(R.id.tv_3)).setText(str);

        String name = "Java传递数据对象给jni 在jni层打印数据";
        PostObject postObject = new PostObject();
        postObject.setName(name);
        mainNativBridge.postValueOBJ2JNI(postObject);
        ((TextView) findViewById(R.id.tv_4)).setText(name);
        mainNativBridge.accessMethod();
        ((TextView) findViewById(R.id.tv_5)).setText("jni调用Java方法");
        mainNativBridge.accessStaticMethod();
        ((TextView) findViewById(R.id.tv_6)).setText("jni调用Java静态方法");
     /*   mainNativBridge.accessFiled();
        ((TextView) findViewById(R.id.tv_7)).setText(mainNativBridge.accessValue);*/

        mainNativBridge.test();

        ///storage/emulated/0 == sdcard
        String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/makevideo/bunny.mp4";
        String target = Environment.getExternalStorageDirectory().getAbsolutePath() + "/makevideo/bunny.h264";

        //使用兼容库就无需判断系统版本
        int hasWriteStoragePermission = ContextCompat.checkSelfPermission(getApplication(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (hasWriteStoragePermission == PackageManager.PERMISSION_GRANTED) {
            //拥有权限，执行操作
            mainNativBridge.makeffmpegInfo(path,target);

        } else {
            //没有权限，向用户请求权限
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
        }


    }

    public void addFragment() {
        getSupportFragmentManager().beginTransaction().add(R.id.content, HomeFragment.Companion.getInstance(), "home").commit();

    }


}
